package com.zjj.lbw.designpattern.factorymethod;

/**
 * @author zhanglei.zjj
 * @description 工厂方法模式
 * @date 2023/7/12 16:06
 */
public class FactoryMethodTest {
    public static void main(String[] args) {
        CarFactory aoDiFactory = new AoDiFactory();
        aoDiFactory.createCar().run();

        CarFactory bmwFactory = new BmwFactory();
        bmwFactory.createCar().run();

    }
}

// 抽象产品
interface Car {
    public void run();
}

// 抽象工厂
interface CarFactory {
    Car createCar();
}

// 具体产品1
class AoDi implements Car {
    public void run() {
        System.out.println("我是奥迪汽车..");
    }
}

// 具体产品2
class Bmw implements Car {
    public void run() {
        System.out.println("我是宝马汽车...");
    }
}

// 具体工厂1
class AoDiFactory implements CarFactory {
    public Car createCar() {
        return new AoDi();
    }
}

// 具体工厂2
class BmwFactory implements CarFactory {
    public Car createCar() {
        return new Bmw();
    }
}